package com.es.esdemo.controller;

import com.es.esdemo.entity.Resp;
import com.es.esdemo.service.CmsService;
import com.es.esdemo.tool.RespTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description
 * @author yanghanwei[yanghanwei@bjpp.com]
 * @date 19:35 2020-11-30
 */
@RestController
@RequestMapping("/es")
public class EsDemoController {

    @Autowired
    private CmsService cmsService;

    /**
     * 创建索引
     * @return
     */
    @RequestMapping("/create")
    public Resp createIndex(){
        return RespTool.buildSuccess(cmsService.createIndex());
    }

    /**
     * 删除索引
     * @return
     */
    @RequestMapping("/delete")
    public Resp deleteIndex(){
        return RespTool.buildSuccess(cmsService.deleteIndex());
    }

    /**
     * 构建数据
     * @return
     */
    @RequestMapping("/rebuild")
    public Resp rebuildIndex(){
        return RespTool.buildSuccess(cmsService.rebuildIndex());
    }

    /**
     * 查询
     * @return
     */
    @RequestMapping("/search")
    public Resp searchIndex(){
        return RespTool.buildSuccess("success");
    }

    /**
     * mysql getList
     * @return
     */
    @RequestMapping("/getList")
    public Resp getList(){
        return RespTool.buildSuccess(cmsService.getList());
    }

    /**
     * ES 查询
     * @param pageNo
     * @param pageSize
     * @param keyword
     * @return
     */
    @RequestMapping("/searchList")
    public Resp searchList(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                           @RequestParam(value = "id", required = false) Integer id,
                           @RequestParam(value = "keyword") String keyword){
        return RespTool.buildSuccess(cmsService.searchList(pageNo, pageSize, id, keyword));
    }

}
